using MicroMsg.Plugin.Sns.Scene;
using MicroMsg.Storage;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.UserContrl
{
	public class CirclePagePicItem : SnsHttpImgCtrlBase
	{
		public delegate void ListItemClick(object sender, object object_0);
		private const string TAG = "CirclePagePicItem";
		private const uint cNShowImg = 1200u;
		private const SolidColorBrush cBrushCoverNormal = null;
		private const double cDMoveRestrict = 25.0;
		private const int cNMaxCacheCnt = 18;
		public bool mBIsDelayLoadImage;
		public BitmapImage mDefaultImg;
		public static DependencyProperty isPlayedProperty = DependencyProperty.Register("imgPlayed", typeof(bool), typeof(CirclePagePicItem), new PropertyMetadata(false));
		private Storyboard mSbShowImg;
		private bool mBIsImageShown;
		public int mNPicIndex = -1;
		private static SolidColorBrush cBrushCoverTouch;
		private bool mBIsClickCancled;
		private static List<CirclePagePicItem> sTimelineItem;
		private bool mBIsEnableTouchEffect = true;
		internal Image imgContent;
		internal Grid gridCover;
		private bool _contentLoaded;
		public event CirclePagePicItem.ListItemClick ItemClick;
		public bool imgPlayed
		{
			get
			{
				return CirclePagePicItem.isPlayedProperty != null && base.GetValue(CirclePagePicItem.isPlayedProperty) != null && (bool)base.GetValue(CirclePagePicItem.isPlayedProperty);
			}
			set
			{
				base.SetValue(CirclePagePicItem.isPlayedProperty, value);
			}
		}
		public CirclePagePicItem()
		{
			this.InitializeComponent();
		}
		public void setImgPlayedOn()
		{
			this.imgPlayed = true;
		}
		public void ShowImg()
		{
			if (this.mBIsImageShown)
			{
				return;
			}
			this.mBIsImageShown = true;
			snsMediaDownloadInfo objReqInfo = new snsMediaDownloadInfo
			{
				snsObjID = base.ObjMediaInfo.nID,
				string_0 = base.ObjMediaInfo.strThumb,
				urlType = (SnsUrlType)base.ObjMediaInfo.nThumbType,
				priority = SnsPriority.LOW
			};
			base.StartRequest(objReqInfo, !this.mBIsDelayLoadImage);
		}
		protected override void ObjectCome(object object_0)
		{
			if (object_0 != null && object_0 is snsMediaDownloadInfo)
			{
				snsMediaDownloadInfo snsMediaDownloadInfo = object_0 as snsMediaDownloadInfo;
				if (snsMediaDownloadInfo.object_0 != null && snsMediaDownloadInfo.object_0 is BitmapImage)
				{
					(snsMediaDownloadInfo.object_0 as BitmapImage).set_CreateOptions(2);
					this.imgContent.set_Source(snsMediaDownloadInfo.object_0 as BitmapImage);
					this.mDefaultImg = null;
				}
				return;
			}
		}
		private void mSbShowImg_Completed(object sender, EventArgs e)
		{
			this.StopShowImg();
		}
		private void StopShowImg()
		{
			if (this.mSbShowImg != null)
			{
				this.mSbShowImg.Stop();
				this.mSbShowImg = null;
			}
			this.imgContent.set_Opacity(1.0);
		}
		protected override void MediaInfoChanged(TloMedia mediaInfo)
		{
			this.imgContent.set_Source(this.mDefaultImg);
			if (base.ObjMediaInfo == null)
			{
				base.StopRequest();
				return;
			}
			this.mBIsImageShown = false;
			this.ShowImg();
		}
		private void btnLayoutRoot_Click(object sender, RoutedEventArgs e)
		{
			this.clicked();
		}
		private void clicked()
		{
			if (this.ItemClick != null)
			{
				this.ItemClick(this, this.mNPicIndex);
			}
		}
		private void Grid_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
		{
			this.mBIsClickCancled = false;
			if (this.mBIsEnableTouchEffect)
			{
				this.gridCover.set_Background(CirclePagePicItem.cBrushCoverTouch);
			}
		}
		private void Grid_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
		{
			Point translation = e.get_DeltaManipulation().get_Translation();
			if (translation.get_X() * translation.get_X() + translation.get_Y() * translation.get_Y() > 25.0)
			{
				this.gridCover.set_Background(null);
				this.mBIsClickCancled = true;
			}
		}
		private void Grid_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
		{
			if (this.mBIsEnableTouchEffect)
			{
				this.gridCover.set_Background(null);
			}
		}
		private void ClickEffectGrid_mClicked(object sender, object args)
		{
			this.clicked();
		}
		public static CirclePagePicItem GetOneItem()
		{
			if (CirclePagePicItem.sTimelineItem != null && CirclePagePicItem.sTimelineItem.get_Count() != 0)
			{
				CirclePagePicItem circlePagePicItem = Enumerable.First<CirclePagePicItem>(CirclePagePicItem.sTimelineItem);
				CirclePagePicItem.sTimelineItem.RemoveAt(0);
				if (circlePagePicItem.get_Parent() == null)
				{
					return circlePagePicItem;
				}
			}
			return new CirclePagePicItem();
		}
		public static int GetCacheCnt()
		{
			if (CirclePagePicItem.sTimelineItem == null)
			{
				return 0;
			}
			return CirclePagePicItem.sTimelineItem.get_Count();
		}
		public static void PushOneItem(CirclePagePicItem item)
		{
			if (item == null)
			{
				return;
			}
			if (CirclePagePicItem.sTimelineItem == null)
			{
				CirclePagePicItem.sTimelineItem = new List<CirclePagePicItem>();
			}
			item.mNPicIndex = -1;
			item.StopRequest();
			item.mBIsDelayLoadImage = false;
			if (item.get_Parent() != null)
			{
				Panel panel = item.get_Parent() as Panel;
				if (panel != null)
				{
					panel.get_Children().Remove(item);
				}
			}
			item.ObjMediaInfo = null;
			item.imgContent.set_Source(null);
			item.ItemClick = null;
			item.mDefaultImg = null;
			if (CirclePagePicItem.sTimelineItem.get_Count() > 18)
			{
				return;
			}
			CirclePagePicItem.sTimelineItem.Add(item);
		}
		public void DisableTouchEffect()
		{
			this.mBIsEnableTouchEffect = false;
		}
		public void EnableTouchEffect()
		{
			this.mBIsEnableTouchEffect = true;
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/Sns/Circle/UI/CirclePagePicItem.xaml", 2));
			this.imgContent = (Image)base.FindName("imgContent");
			this.gridCover = (Grid)base.FindName("gridCover");
		}
		static CirclePagePicItem()
		{
			// Note: this type is marked as 'beforefieldinit'.
			SolidColorBrush solidColorBrush = new SolidColorBrush();
			solidColorBrush.set_Color(Color.FromArgb(153, 0, 0, 0));
			CirclePagePicItem.cBrushCoverTouch = solidColorBrush;
			CirclePagePicItem.sTimelineItem = new List<CirclePagePicItem>();
		}
	}
}
